<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<link rel="stylesheet" href="${ctxPath}/static/assets/aui/css/aui.css" media="all">
		<!-- jQuery Include -->
		<script type="text/javascript" src="${ctxPath}/static/assets/scripts/jquery.min.js"></script>
		<!-- Mobiscroll JS and CSS Includes -->
		<script type="text/javascript" src="${ctxPath}/static/assets/scripts/mobiscroll.custom.min.js"></script>
		<link href="${ctxPath}/static/assets/css/mobiscroll.custom.min.css" rel="stylesheet" type="text/css" />
		<title>注册页面</title>
		<style>
			body {
				margin: 0;
				padding: 0;
				font-size: 18px;
				text-align: -moz-left;
			}
			
			.aui-list-item-input>input {
				padding: 10px;
			}
			
			.aui-list-item-input>select {
				padding: 10px;
			}
			
			.aui-list-item-input>label {
				padding: 10px;
			}

			.section label {
				position: absolute;
				left: 0;
				top: 0;
				bottom: 0;
				height: 32px;
				line-height: 32px;
				font-size: 12px;
			}
			
			.section>select,
			.section>input {
				width: 100%;
				height: 100%;
				display: block;
				padding: 0 10px;
				box-sizing: border-box;
			}

			.aui-iconfont {
				z-index: 14;
				position: relative;
			}
			.aui-list-item-label{
				font-size: 14px;
			}
			.aui-list-item-input>input{
				font-size: 14px;
			}
		</style>
	</head>

	<body>
		<!--
                	作者：offline
                	时间：2019-06-07
                	描述：顶部通知
                -->
		<div class="aui-content aui-margin-b-15">
			<ul class="aui-list aui-form-list">
				<li >
					<header class="aui-bar aui-bar-nav">
					    <a class="aui-pull-left aui-btn"  id="retn">
					        <span class="aui-iconfont aui-icon-left"></span>返回
					    </a>
					    <div class="aui-title">完善资料</div>
					</header>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							昵称
						</div>
						<div class="aui-list-item-input">
							<input type="text" id="name" placeholder="请输入昵称">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							性别
						</div>
						<div class="aui-list-item-input">
							<label><input class="aui-radio" type="radio" name="demo1" value="1" checked> 男</label>
							<label><input class="aui-radio" type="radio" name="demo1" value="0"> 女</label>
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							出生年月
						</div>
						<div class="aui-list-item-input">
							<input type="text" name="birthday" id="birthday" placeholder="选择出生年月" readonly="readonly">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							手机号
						</div>
						<div class="aui-list-item-input">
							<input style="color: gray;" readonly="readonly" type="number" id="phone" placeholder="情输入正确的手机号码" maxlength="11">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							公司职务&nbsp;<div class="aui-label aui-label-info">选填</div>
						</div>
						<div class="aui-list-item-input">
							<input type="text" id="position" placeholder="请输入公司职务" maxlength="20">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							身份证&nbsp;<div class="aui-label aui-label-info">选填</div>
						</div>
						<div class="aui-list-item-input">
							<input type="text" id="idCard" placeholder="请输入身份证" maxlength="18">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							区域
						</div>
						<div class="aui-list-item-input">
							<input type="text" id="picker" placeholder="所在区域">
						</div>
					</div>
				</li>
				<li class="aui-list-item">
					<div class="aui-list-item-inner">
						<div class="aui-list-item-label">
							个性签名&nbsp;<div class="aui-label aui-label-info">选填</div>
						</div>
						<div class="aui-list-item-input">
							<input type="text"  id="signature" placeholder="请输入个性签名">
						</div>
					</div>
				</li>
			</ul>
			</div>
		
				<!--<p style="margin-bottom: 37px;">
					<div onclick="showDefault('loading')" class="aui-btn aui-btn-primary  aui-btn-sm" style="width: 200px;margin-left: 87px;" tapmode >下一步</div>
				</p>-->
				<p>
					<div onclick="showDefault()" tapmode class="aui-btn aui-btn-info aui-btn-block aui-btn-outlined aui-btn-sm">保存</div>
				</p>
	</body>
	<!--js类引用-->
	<script src="${ctxPath}/static/assets/scripts/picker.min.js"></script>
	<script type="text/javascript" src="${ctxPath}/static/assets/scripts/city.js"></script>
	<script type="text/javascript" src="${ctxPath}/static/assets/scripts/index.js"></script>
	<!--
    	作者：offline
    	时间：2019-06-06
    	描述：日期
    -->
	<script type="text/javascript">
		var theme = "ios";
		var mode = "scroller";
		var display = "bottom";
		var lang = "zh";
		$('#birthday').mobiscroll().date({
			theme: theme,
			mode: mode,
			display: display,
			lang: lang
		});
	</script>

	<script type="text/javascript" src="${ctxPath}/static/assets/aui/script/aui-toast.js"></script>
	<script type="text/javascript">
		//判断是否登录
		var  user=localStorage.getItem("userInfo");//以“key”为名称存储一个值“value”
		if(!user){
			location.href="${ctxPath}/wechat/public/toLoginPage";//未实现
		}
		$("#img").show();
		var userInfo = JSON.parse(user); // --> parse error
		console.log(userInfo);
		$(function () {
			init(userInfo);
            //增加replaceAll方法
            String.prototype.replaceAll = function(s1,s2){
                return this.replace(new RegExp(s1,"gm"),s2);
            }
		})
		function init(userInfo){
			$("#name").val(userInfo.name);//昵称
			$("#birthday").val(userInfo.birthday?dateToString(new Date(userInfo.birthday)):"");//出生年月
			$("#phone").val(userInfo.phone);//手机号
			$("#idCard").val(userInfo.idCard);//身份证
			$("#signature").val(userInfo.signature);//个性签名
			$("#picker").val(userInfo.area);//所在区域
			$(".aui-radio").eq(userInfo.sex==1?0:1).attr("checked","checked");
			$("#position").val(userInfo.position);
		}

		$("#retn").click(function(){
			location.href ="${ctxPath}/wechat/public/toMinePage";
		})
		function dateToString(date){
			var year = date.getFullYear();
			var month =(date.getMonth() + 1).toString();
			var day = (date.getDate()).toString();
			if (month.length == 1) {
				month = "0" + month;
			}
			if (day.length == 1) {
				day = "0" + day;
			}
			var dateTime = year + "/" + month + "/" + day;
			return dateTime;
		}
		var  data={};
		//更新数据
		function showDefault() {
			var  name=$("#name").val();
			var  birthday=$("#birthday").val()
			var phone=$("#phone").val();
			var picker=$("#picker").val();//所在区域
			var  sex=　parseInt($(".aui-radio:checked").val());
			var  idCard=$("#idCard").val();
			var  position=$("#position").val();
			var  signature=$("#signature").val();
			//信息校验
			var result=checkInfo(name,birthday,phone,picker);
			if(!result){
				return;
			}
			data.name=name;
			data.birthday=timeTransform(birthday);
			data.phone=phone;
			data.area=picker.trim().replaceAll(" ","-");
			data.id=userInfo.id;
			data.age=ages(birthday);
			data.sex=sex;
			data.idCard=idCard;
			data.position=position;
			data.signature=signature;
			//更新数据
			$.ajax({
				type: "POST",
				url: "${ctxPath}/bizConsumer/update",
				data: data,
				dataType: "json",
				success: function (result) {
					if (result.status == "0000") {
						localStorage.setItem("userInfo",JSON.stringify(result.data));//以“key”为名称存储一个值“value”
                        apiready = function(){
                            api.parseTapmode();
                        }
                        var toast = new auiToast({
                        })
                        toast.success({
                            title:"保存成功",
                            duration:2000
                        });
						location.href="${ctxPath}/wechat/public/toMinePage";//未实现
					}
				}
			});
		}
		
		//信息校验
		function checkInfo(name,birthday,phone,picker) {
			apiready = function(){
				api.parseTapmode();
			}
			var toast = new auiToast({
			})
			if(!name){
				toast.fail({
					title:"请填写昵称",
					duration:2000
				});
				return false;
			}
			if(!birthday){
				toast.fail({
					title:"请选择出生年月",
					duration:2000
				});
				return false;
			}
			if(!phone){
				toast.fail({
					title:"请填写手机号",
					duration:2000
				});
				return false;
			}
			var pattern = /^1[0-9]{10}$/;
			if(!pattern.test(phone)){
				toast.fail({
					title:"请输入正确的手机号",
					duration:2000
				});
				return;
			}
			if(!picker){
				toast.fail({
					title:"请选择所在区域",
					duration:2000
				});
				return false;
			}
			return true;
		}

		function   ages(str) {
			var   r   =   str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
			if(r==null)return   false;
			var   d=   new   Date(r[1],   r[3]-1,   r[4]);
			if(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]) {
				var   Y=new   Date().getFullYear();
				return (Y-r[1]);
			}
			return("输入的日期格式错误！");
		}
        function timeTransform(time) {
            var d = new Date(time);
            var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
            return times;
        }
	</script>

</html>